package com.iflytek.edu.service;

import com.iflytek.edu.entity.User;
import com.iflytek.edu.common.base.BaseService;
import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Chain;
import org.nutz.dao.Dao;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.IocBean;

/**
 * @author Jack Q on 2017/2/5.
 */
@IocBean(args = {"refer:dao"})
public class UserService extends BaseService<User>{

    public UserService(Dao dao) {
        super(dao);
    }

    //测试事务
    @Aop(TransAop.READ_COMMITTED) // TransAop里面定义5个常量,分别对应不同级别的事务拦截器
    public void testTrans(User user) {
        dao().insert(user);
        //update 异常了
        dao().update(User.class, Chain.make("username","xxxddddddddddddddddddddddddddddddddddddddddddddddddddddddd"),null);
        // 务必注意,必须抛出异常,才能回滚!! 是抛出,不能被catch吃掉.
    }
}
